//
//  AccountCurrency.m
//  ImGuider
//
//  Created by 李陆涛 on 2018/1/18.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "AccountCurrency.h"
#import "AccountCell.h"

@interface AccountCurrency ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *commitBtn;

@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic) NSString *currency;

@end
@implementation AccountCurrency

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
}

- (void)setup {
    
    self.title = MYLocalizedString(@"SETTING_CURRENCY_TITLE", nil);
    
    self.dataSource = @[@{@"name" : MYLocalizedString(@"SETTING_CURRENCY_CNY", nil), @"code" : @"CNY"},@{@"name" : MYLocalizedString(@"SETTING_CURRENCY_USD", nil), @"code" : @"USD"}];
    
    
    [self.commitBtn setTitle:MYLocalizedString(@"PUBLIC_CONFIRM", nil) forState:UIControlStateNormal];
    self.tableView.tableFooterView = [UIView new];
    
    self.currency = [AppManager sharedManager].currencyCode;
    
    [self.tableView reloadData];
}
- (IBAction)settingLan:(id)sender {
    
    
    if ([[AppManager sharedManager].currencyCode isEqualToString:self.currency]) {
        
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    [AppManager sharedManager].currencyCode = self.currency;
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    NSDictionary *dict = self.dataSource[indexPath.row];
    
    AccountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountLanguageCell"];
    
    [cell configWithDict:dict];
    
    cell.choosed = [dict[@"code"] isEqualToString:self.currency];
    
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    NSDictionary *dict = self.dataSource[indexPath.row];
    
    self.currency = dict[@"code"];
    
    [tableView reloadData];
}




@end

